<?php

namespace App\Module\Api\Controllers;



use App\Exceptions\Customize\ParamsException;
use App\Module\Api\Controllers\Request\BindMobileRequest;
use App\Module\Api\Validator\BindMobileValidator;
use App\System\Cis\Repositories\CisUserRepository;

class BindMobileController extends Controller
{
     public function __construct()
     {
             $this->query = new BindMobileRequest();
             parent::__construct();
     }

    public function index()
    {
        (new BindMobileValidator())->check();
        $action = $this->query->action;
        if ($action ==1){
//            新用户绑定
            $sessionId = request()->s;
//            根据sessionId获取用户id
            $userInfo = \Cache::get($sessionId);
            $userId = $userInfo['userInfo']['id'];
//            根据用户id更新用户手机号
            $user = CisUserRepository::getInstance();
            $flag = $user->updateMobileById($userId,$this->query->mobile);
            if (!$flag){
                throw new ParamsException([
                    'error_code' => '1000',
                    'message'    => '绑定失败！',
                ]);
            }
            $q=['d'=>'绑定成功'];
                return apiResponse($q);
        }

    }
}
